package cn.test.controller;

import cn.test.service.UserService;
import cn.test.pojo.entity.SysUser;
import cn.test.vo.req.LoginReqVo;
import cn.test.vo.resp.LoginRespVo;
import cn.test.vo.resp.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author bigBear
 * @version 1.0
 * @date 2024-10-16 20:49
 */
@RestController
@RequestMapping("/api")
@Api(tags = "用户API测试接口")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 根据用户名查询用户信息
     *
     * @param name
     * @return
     */
    @ApiOperation(value = "根据用户名查询用户信息")
    @GetMapping("/user/{userName}")
    public SysUser findByUserName(@PathVariable("userName") String name) {
        return userService.findByUserName(name);
    }

    /**
     * 用户登录
     *
     * @param loginReqVo
     * @return
     */
    @ApiOperation(value = "用户登录")
    @PostMapping("/login")
    public R<LoginRespVo> login(@RequestBody LoginReqVo loginReqVo) {
        return userService.login(loginReqVo);
    }

    /**
     * 生成登录验证码
     *
     * @return
     */
    @ApiOperation(value = "生成登录验证码")
    @GetMapping("/captcha")
    public R<Map> getCaptchaCode() {
        return userService.getCaptchaCode();
    }
}
